// JavaScript Document

var detail_show = 0;
//
var mouse_click = 0;
// if click a menu set to 1 and set 'click_menu' to click element's id
var click_menu = "";
//
var news_id = 1;

var mList = {
	"footer-menu-1" : "body-footer-info1",
	"footer-menu-2" : "body-footer-info2",
	"footer-menu-3" : "body-footer-info3",
	"footer-menu-4" : "body-footer-info4",
	"footer-menu-5" : "body-footer-info5",
	"menu-image-text1" : "body-content-info1",
	"menu-image-text2" : "body-content-info2",
	"menu-image-text3" : "body-content-info3",
	"menu-image-text4" : "body-content-info4",
	"menu-image-text5" : "body-content-info5",
	"menu-image-text6" : "body-content-info6",
	"menu-image-text7" : "body-content-info7",
    "login" : "body-login",
	"reg" : "body-login-reg1",
	"video" : "body-video",
	"news2" : "body-news2",
	"news1" : "body-news1"
};

function setActiveStyleSheet(title) {
	document.getElementsByTagName("link")[0].href = "" + title;
}

function ScreenWidth(CSS1, CSS2, CSS3, CSS4) {

/*	if ((screen.width >= 1600)) {
		setActiveStyleSheet(CSS1);
	} else {
*/		if ((screen.width >= 1366)) {
			setActiveStyleSheet(CSS1);      //prd.2.1920.css
		} else {

			if (screen.width == 768 && screen.height == 1024
					|| (screen.width >= 1024)) {

				setActiveStyleSheet(CSS3);   //prd.2.1024.css
			} else {

				setActiveStyleSheet(CSS4);   //prd.2.css
			}
		}
/*	}*/
}

showdetail = function(v_compent) {
	var dList = {
		"member-item11" : "member-item-detail11",
		"member-item12" : "member-item-detail12",
		"member-item1" : "member-item-detail1",
		"member-item2" : "member-item-detail2",
		"member-item3" : "member-item-detail3",
		"member-item4" : "member-item-detail4",
		"member-item5" : "member-item-detail5",
		"member-item6" : "member-item-detail6",
		"member-item7" : "member-item-detail7",
		"member-item8" : "member-item-detail8",
		"member-item9" : "member-item-detail9"
	};

	var itextContent = document.getElementById(v_compent.id).textContent;
	var iclass = document.getElementById(dList[v_compent.id]).className;
	if (iclass == "member-item-detail-hidden") {
		document.getElementById(dList[v_compent.id]).className = "member-item-detail";
		// document.getElementById(v_compent.id).textContent = "-" +
		// itextContent;
		document.getElementById(v_compent.id).textContent = itextContent
				.replace(/\+/, "-");
	} else {
		document.getElementById(dList[v_compent.id]).className = "member-item-detail-hidden";
		// document.getElementById(v_compent.id).textContent = "+" +
		// itextContent;
		document.getElementById(v_compent.id).textContent = itextContent
				.replace(/\-/, "+");
	}

};

disp_click = function(v_compent, v_data, v_menuname) {
	if (mouse_click == 1 && v_data == click_menu ) {
		bodyClose(v_compent, 1);
		return;
	}
	bodyClose(v_compent, 1);


	document.getElementById(v_data).className = "body-content-info";
	// disp(v_compent, v_menuname);
	
	detail_show = 1;

	mouse_click = 1;
	click_menu = v_data;
};

disp = function(v_compent, v_data) {
	var pList = {
		"body-content1" : "url(scripts/prd/pic1.jpg)",
		"body-content2" : "url(scripts/prd/pic2.jpg)",
		"body-content3" : "url(scripts/prd/pic3.jpg)",
		"body-content4" : "url(scripts/prd/pic4.jpg)",
		"body-content5" : "url(scripts/prd/pic5.jpg)"
	};

	if (mouse_click == 1) {
		return;
	}

	bodyClose2();

	document.getElementById(v_data).className = "body-content";

	document.getElementById("body").style.backgroundImage = pList[v_data];

	/*
	 * if (v_data == "body-content1") {
	 * document.getElementById("body").style.backgroundImage = "url(pic1.jpg)";
	 * if (window.navigator.userAgent.indexOf("MSIE") >= 1){
	 * document.getElementById("body").style.filter =
	 * "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='pic1.jpg',
	 * sizingMethod='scale')"; } }
	 */
};

disp_menu = function(v_compent, v_flag) {
	// v_data will show menu's id
	// v_flag 1 click 0 preview

	// alert(v_compent.id + " " + mList[v_compent.id]);

	id = v_compent.id;

	if (v_flag == 1) {
		$("div#menu ul li a").removeClass("avisited");
		mouse_click = 1;
		click_menu = mList[v_compent.id];
		detail_show = 1;
	}

	bodyClose1();
	bodyClose2();

	document.getElementById(mList[v_compent.id]).className = "body-content-info";

	detail_show = 1;

};

bodyClose = function(v_compent, v_flag) {
	// v_compent : focus element
	// v_flag : 1 click close 0 preview close
	if (v_flag == 1) {
		mouse_click = 0;
		click_menu = "";
	} else if (mouse_click == 1 && click_menu == v_compent.id) {
		return;
	}

	bodyClose1();
	bodyClose2();
	detail_show = 0;

	if (mouse_click == 1) {
		document.getElementById(click_menu).className = "body-content-info";
		//clearTimeout(interval); // stop Interval
	}
};

bodyClose2 = function() {

};

news_choice = function(v_step) {

	var nid = "news-" + news_id;
	document.getElementById(nid).className = "news-context-hidden";
	news_id = news_id + v_step;
	if (news_id == 0) {
		news_id = 3;
	}
	if (news_id == 4) {
		news_id = 1;
	}
	nid = "news-" + news_id;
	document.getElementById(nid).className = "news-context";

};

bodyClose1 = function() {

	if (mouse_click != 1) {
		$("div#menu ul li a").removeClass("avisited");
		$("div#menu ul li").removeClass("avisited");
	}

	for (x in mList) {
		document.getElementById(mList[x]).className = "body-content-info-hidden";
	}
	
	//run();   // restart Interval

};

function registerMember() {
	var _Name = $.trim($('#Name').val());
	var _Gender = $.trim($('#Gender').val());
	var _serviceCompany = $.trim($('#serviceCompany').val());
	var _companyAddr = $.trim($('#companyAddr').val());
	var _position = $.trim($('#position').val());
	var _birthDate = $.trim($('#birthDate').val());
	var _mobile = $.trim($('#mobile').val());
	var _email = $.trim($('#email').val());
	var _idCard = $.trim($('#idCard').val());
	var _citizenship = $.trim($('#citizenship').val());
	var _urgenContact = $.trim($('#urgenContact').val());
	var _companyMemo = $.trim($('#companyMemo').val());
	var _regPwd = $.trim($('#regPwd').val());
	var _confirm_regPwd = $.trim($('#confirm_regPwd').val());
	var _channel_id = $.trim($('#channel').val());
	var _o_cust = $.trim($('#cust').val());

	var _regName = _mobile;
	if (_Name == "") {
		alert("姓名为空！");
		return false;
	}
	if (_serviceCompany == "") {
		alert("服务机构为空！");
		return false;
	}
	if (_companyAddr == "") {
		alert("机构地址为空！");
		return false;
	}
	if (_position == "") {
		alert("职位为空！");
		return false;
	}
	if (_birthDate == "") {
		alert("出生年月为空！");
		return false;
	}
	var bdate = /[0-9]{4}-[0-9]{2}/.test(_birthDate);
	if (!bdate) {
		alert("出生年月格式不正确，正确格式为'1980-03'");
		return false;
	}
	if (_email == "") {
		alert("邮箱地址为空！");
		return false;
	}
	if (_email.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == -1) {
		alert("请输入正确的邮件地址！");
		return;
	}

	if (_mobile == "") {
		alert("手机号码为空！");
		return false;
	}

	if (_idCard == "") {
		alert("身份证号码为空！");
		return false;
	}
	if (!IdCardValidate(_idCard)) {
		alert("请输入正确的身份证号码！");
		return false;
	}

	if (_regPwd == "") {
		alert("密码为空！");
		return false;
	}
	if (_regPwd != _confirm_regPwd) {
		alert("两次输入的密码不一致！");
		return false;
	}

	var code = $("#veryCodeReg").val();
	if (code == "") {
		alert("请输入验证码！");
		return false;
	}
	$.ajax({
		async : false,
		type : "POST",
		url : "ResultServlet",
		data : "c=" + code,
		success : function(data) {
			returnData = data;
		},
		error : function(data) {
			returnData = data;
			alert("验证过程出错！");
			return false;
		}
	});
	if (returnData == "false") {
		alert("验证码不正确！");
		changeImgReg();
		return false;
	}
	var o = {
		state : "added",
		username : _regName,
		password : _regPwd,
		member_id : _regName,
		name : _Name,
		sex : _Gender,
		service_company : _serviceCompany,
		company_add : _companyAddr,
		position : _position,
		brith_date : _birthDate,
		mobile : _mobile,
		email : _email,
		id_card : _idCard,
		citizenship : _citizenship,
		urgent_contact : _urgenContact,
		company_profile : _companyMemo,
		channel_id : _channel_id,
		o_cust : _o_cust
	};

	var json = mini.encode([ o ]);
	$.ajax({
		type : "POST",
		url : "/prd/user/save",
		data : {
			data : json,
			type : 'M'
		},
		success : function(text) {
			alert(text);
			$("#loginUser").val(_regName);
			$("#loginPasswd").val(_regPwd);
			$("#mainForm").submit();
		},
		error : function(jqXHR, textStatus, errorThrown) {
			alert("注册失败");
		}
	});
}

function prdlogin() {

	var returnData = "";
	var returnCode = "";
	var _username = "";
	var _password = "";

	_username = $.trim($('#username').val());
	_password = $.trim($('#pwd').val());

	if (_username == "") {
		alert("手机号码为空！");
		return false;
	}

	var code = $("#veryCode").val();
	if (code == "") {
		alert("请输入验证码！");
		return false;
	}
	$.ajax({
		async : false,
		type : "POST",
		url : "ResultServlet",
		data : "c=" + code,
		success : function(data) {
			returnData = data;
		},
		error : function(data) {
			returnData = data;
			alert("验证过程出错！");
			return false;
		}
	});
	if (returnData == "false") {
		alert("验证码不正确！");
		changeImg();
		return false;
	}
	// var o = {
	// username : _username,
	// password : _password
	// };
	// var json = mini.encode([ o ]);
	// $.ajax({
	// type : "POST",
	// url : "/prdclub/login",
	// data : "username=\""+_username+"\"&password=\""+_password+"\"",
	// success : function(data) {
	// //alert(data);
	// return;
	// }
	// });

	// $("#mainForm").attr("action","${pageContext.request.contextPath
	// }/login.shtml");
	// $("#mainForm").submit();

	return true;
}

function OnFocusFun(element, elementvalue) {
	if (element.value == elementvalue) {
		element.value = "";
		element.style.color = "#333";
	}
}
// ///////////////////////////////////////////////////////////////////////////////////////////////////
// var oldalert = alert;
function alert1(message) {
	var dlgArg = new Object();

	dlgArg.message = message;
	// oldalert(message);
	// window.showModelessDialog("ExtOVRDMSGS.jsp?overrideAllowed=" +
	// overideAllowed + "&type=" + attr, message,
	// "dialogLeft:325;dialogTop:270;dialogHeight:200px;dialogWidth:400px;resizable:no;scroll:no;status:no");
	window.showModalDialog("alert.html", dlgArg,
			"dialogWidth:400px; dialogHeight:300px");
	// msgbox('标题','内容','点击确认应执行的函数','是否显示取消按钮','焦点位置');
	// //msgbox('alert',message,'',null,null);
}

function get_width() {
	return (document.body.clientWidth + document.body.scrollLeft);
}
function get_height() {
	return (document.body.clientHeight + document.body.scrollTop);
}
function get_left(w) {
	var bw = document.body.clientWidth;
	var bh = document.body.clientHeight;
	w = parseFloat(w);
	return (bw / 2 - w / 2 + document.body.scrollLeft);
}
function get_top(h) {
	var bw = document.body.clientWidth;
	var bh = document.body.clientHeight;
	h = parseFloat(h);
	return (bh / 2 - h / 2 + document.body.scrollTop);
}
function create_mask() {// 创建遮罩层的函数

	var mask = document.createElement("div");
	mask.id = "mask";
	mask.style.position = "absolute";
	mask.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=4,opacity=25)";// IE的不透明设置

	mask.style.opacity = 0.4;// Mozilla的不透明设置

	mask.style.background = "black";
	mask.style.top = "0px";
	mask.style.left = "0px";
	mask.style.width = get_width();
	mask.style.height = get_height();
	mask.style.zIndex = 1000;
	document.body.appendChild(mask);
}
function create_msgbox(w, h, t) {// 创建弹出对话框的函数

	var box = document.createElement("div");
	box.id = "msgbox";
	box.style.position = "absolute";
	box.style.width = w;
	box.style.height = h;
	box.style.overflow = "visible";
	box.innerHTML = t;
	box.style.zIndex = 1001;
	document.body.appendChild(box);
	re_pos();
}
function re_mask() {
	/*
	 * 更改遮罩层的大小,确保在滚动以及窗口大小改变时还可以覆盖所有的内容
	 */
	var mask = document.getElementById("mask");
	if (null == mask)
		return;
	mask.style.width = get_width() + "px";
	mask.style.height = get_height() + "px";
}
function re_pos() {
	/*
	 * 更改弹出对话框层的位置,确保在滚动以及窗口大小改变时一直保持在网页的最中间
	 */
	var box = document.getElementById("msgbox");
	if (null != box) {
		var w = box.style.width;
		var h = box.style.height;
		box.style.left = get_left(w) + "px";
		box.style.top = get_top(h) + "px";
	}
}
function remove() {
	/*
	 * 清除遮罩层以及弹出的对话框
	 */
	var mask = document.getElementById("mask");
	var msgbox = document.getElementById("msgbox");
	if (null == mask && null == msgbox)
		return;
	document.body.removeChild(mask);
	document.body.removeChild(msgbox);
}
function msgbox(title, text, func, cancel, focus) {
	/*
	 * 参数列表说明: title :弹出对话框的标题,标题内容最好在25个字符内,否则会导致显示图片的异常 text
	 * :弹出对话框的内容,可以使用HTML代码,例如<font color='red'>删除么?</font>,如果直接带入函数,注意转义 func
	 * :弹出对话框点击确认后执行的函数,需要写全函数的引用,例如add(),如果直接带入函数,注意转义。
	 * cancel:弹出对话框是否显示取消按钮,为空的话不显示,为1时显示 focus
	 * :弹出对话框焦点的位置,0焦点在确认按钮上,1在取消按钮上,为空时默认在确认按钮上 Author:Jedliu Blog
	 * :Jedliu.cublog.cn 【网页转载请保留版权信息,实际使用时可以除去该信息】
	 */
	create_mask();
	var temp = "<table width=\"355\" height=\"127\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"font:14px Verdana, Geneva, Arial, Helvetica, sans-serif\">";
	temp += "<tr><td background=\"msgbox/alert_01.gif\" width=\"355\" height=\"22\" style=\"padding-left:8px;padding-top:2px;font-weight: bold;color:white;\">"
			+ title + "</td></tr>";
	temp += "<tr><td background=\"msgbox/alert_02.gif\" width=\"355\" height=\"75\" style=\"padding-left:6px;padding-right:2px;padding-bottom:10px;\">&nbsp;<img src=\"msgbox/alert_mark.gif\">&nbsp;"
			+ text + "</td>";
	temp += "</tr><tr><td width=\"355\" height=\"22\" align=\"center\" background=\"msgbox/alert_03.gif\"><input name=\"msgconfirmb\" type=\"button\" id=\"msgconfirmb\" value=\"确认\" onclick=\"remove();"
			+ func + ";\">";
	if (null != cancel) {
		temp += "&nbsp;&nbsp;<input name=\"msgcancelb\" type=\"button\" id=\"msgcancelb\" value=\"取消\" onclick=\"remove();\"></td>";
	}
	temp += "</tr><tr><td background=\"msgbox/alert_04.gif\" width=\"355\" height=\"8\"></td></tr></table>";
	create_msgbox(400, 200, temp);
	if (focus == 0 || focus == "0" || null == focus) {
		document.getElementById("msgconfirmb").focus();
	} else if (focus == 1 || focus == "1") {
		document.getElementById("msgcancelb").focus();
	}
}
function re_show() {
	/*
	 * 重新显示遮罩层以及弹出窗口元素
	 */
	re_pos();
	re_mask();
}
function load_func() {
	/*
	 * 加载函数,覆盖window的onresize和onscroll函数
	 */
	window.onresize = re_show;
	window.onscroll = re_show;
}
// ///////////////////////////////////////////////////////////////////////////////////////////////////

function openwin() {
	OpenWindow = window.open("", "newwin",
			"height=250, width=250,toolbar=no,scrollbars=" + scroll
					+ ",menubar=no");
	// 写成一行
	OpenWindow.document.write("<TITLE>例子</TITLE>");
	OpenWindow.document.write("<BODY BGCOLOR=#ffffff>");
	OpenWindow.document.write("<h1>Hello!</h1>");
	OpenWindow.document.write("New window opened!");
	OpenWindow.document.write("</BODY>");
	OpenWindow.document.write("</HTML>");
	OpenWindow.document.close();
}

// 注册信息
function reg() {
	var regType = $("input[name=regType]:checked").val();
	var mgpwd = "";
	var pwdType = "";
	var pass = /^\d{6}$/;
	var cardNo = "";
	var mail = $("#email").val();
	var userName = $("#userName").val();
	var phone = $("#phoneNo").val();
	var passWord = document.getElementById("regPwd").value;
	var phoneCode = $("#phoneCode").val();

	if (IsEmpty(passWord) || phone == "请输入您的手机号码" || phoneCode == "") {
		$("#error").attr("style", "display:");
		$("#t_error").text("必填项不能为空");
		return false;
	}

	if (passWord.length < 6) {
		$("#passWord1").text("请输入6位数字密码");
		$("#passWord1").show();
		document.getElementById("passWord1").className = 'list_error';
	} else {
		if ($("#e_password").val() != "") {
			mgpwd = $("#e_password").val();
			pwdType = "0";
		} else {
			mgpwd = strEnc($("#compwdkeybon").val());
			pwdType = "1";
		}

		if (pwdType == "0" && passWord == "******") {
			$("#passWord1").text("输入正确");
			$("#passWord1").show();
			document.getElementById("passWord1").className = 'list_right';
		}

		if (pwdType == "1") {
			if (pass.test(passWord)) {
				$("#passWord1").text("输入正确");
				$("#passWord1").show();
				document.getElementById("passWord1").className = 'list_right';
			} else {
				$("#passWord1").text("请输入6位数字密码");
				$("#passWord1").show();
				document.getElementById("passWord1").className = 'list_error';
			}
		}
	}
	checkPhoneCode();
	var mobile1 = document.getElementById("mobile").className;
	var passWord1 = document.getElementById("passWord1").className;
	var email1 = document.getElementById("email1").className;
	var cardNo1 = document.getElementById("cardNo1").className;
	var phoneCode1 = document.getElementById("phoneCode1").className;
	var userName1 = document.getElementById("userName1").className;

	if (email1 == "list_right") {
		mail = $("#email").val();
	}

	if (userName1 == "") {
		userName = $("#userName").val();
	}

	if (passWord1 == "list_error" || email1 == "list_error"
			|| phoneCode1 == "list_error" || mobile1 == "list_error"
			|| userName1 == "list_error") {
		$("#error").attr("style", "display:");
		$("#t_error").text("请确保输入的内容正确");
		return false;
	} else {
		var miugo = document.getElementById("Miugo");
		var orderid = orderId();
		if (regType == 1) {// 嘀卡注册
			try {
				var json = getEcardToneJson(33029);
				json.OrderId = orderid;
				json.TransAmt = 0;
				json.CAIC = CAIC;
				json.PIN = passWord;
				json.Phone = phone;
				json.TxnPIN = passWord;
				json.IdType = '0X';
				json.Email = mail;
				json.Name = userName;
				miugo.RegCallback(regBack);
				miugo.Trade(json);
			} catch (e) {
				$("#error").attr("style", "display:");
				$("#t_error").text("浏览器不支持嘀卡操作，请选择卡号操作");
				return false;
			}
		} else if (regType == 2 || regType == 3) {// 持卡注册
			urlstr = "${pageContext.request.contextPath }/reg.do";
			cardNo = $("#cardNo").val();
			if (regType == 2) {
				if (IsEmpty(cardNo)) {
					$("#error").attr("style", "display:");
					$("#t_error").text("必填项不能为空");
					return false;
				} else if (cardNo1 == "list_error") {
					$("#error").attr("style", "display:");
					$("#t_error").text("请确保输入的内容正确");
					return false;
				}
			}
			if (regType == 3) {
				cardNo = "";
			}

			$.ajax({
						type : "POST",
						url : encodeURI(urlstr),
						data : {// 发送的数据
							m : "r",
							phone : phone,
							cardNo : cardNo,
							email : mail,
							regType : regType,
							pin : mgpwd,
							mgQpwd : mgpwd,
							qpwdType : pwdType,
							name : userName,
							pwdType : pwdType
						},
						dataType : "json",
						async : false,
						success : function(data) {
							if (data.result == '1' || data.result == '4') {
								if (regType == 3 || regType == 2) {
									document.getElementById("mailOrPhone").value = data.cardNo;
									$("#regTypeOk").val(regType);
									$("#awardAtm").val(data.awardAtm);
									$("#awardType").val(data.awardType);
									$("#name").val(userName);
									document.regOK.submit();
								}
							} else if (data.result == '2') {
								$("#t_error").text(data.resultdes);
								$("#error").show();
							}
						}
					});
		}
	}
}